<?php

function getViewTimeMsg($timestamp): string
{
    $now = time();
    $diffSeconds = $now - $timestamp;//差值
    if ($diffSeconds <= 60) {//1分钟之内
        $msg = '刚刚';
    } elseif ($diffSeconds <= 3600) {//1个小时之内
        $msg = intval($diffSeconds / 60) . '分钟前';
    } elseif ($diffSeconds <= 24 * 3600) {//24小时之内
        $msg = intval($diffSeconds / 3600) . '小时前';
    } else {//24小时之前
        $msg = date('Y-m-d', $timestamp);
    }

    return $msg;
}